// components/tab-bar/index.js
import {toWeb} from '../../utils/toWeb'
const app = getApp()
Component({
    properties: {
        active: {
            type: String,
        }
    },
    options: {
        addGlobalClass: true
    },
    data: {},
    lifetimes: {
        attached: function () {

        }
    },
    methods: {
        scanCode() {
            app.scanCode()
        },
        toIndex() {
            const pages = getCurrentPages()
            const len = pages.length

            if(this.data.active === '1'){
                return
            }
            if (pages[len - 2] && pages[len - 2].route.includes('package-sell/index/index')) {
                wx.navigateBack({
                    delta: 1
                })
                return
            }
            const is = pages.some(item => {
                return item.route.includes('package-sell/index/index')
            })
            if (!is) {
                wx.redirectTo({
                    url: '/package-sell/index/index'
                })
            }
        },
        // 跳转首页
        goToSellIndex() {
            this.triggerEvent('pageToTop')
            // let url = '/package-sell/index/index'
            // let myComId = wx.getStorageSync('package_BSell_Enter')
            // if (myComId) {// 首页直接跳进来的
            //   console.log('--isMainPageEnterBSell:--' + true)
            //   url = '/package-sell/index/index?isMainPageEnter=true'
            // } else {
            //   console.log('--isMainPageEnterBSell:--' + false)
            // }

            // console.log('跳转BSell首页:' + url)
            // wx.redirectTo({
            //   url: url,
            // })
        },
        gotoWeb() {
            toWeb({
                src: 'https://www.laikang.com/',
                title: '来康'
            })
        }
    }
})
